#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{

  int fd1, fd2, count;
  fd1 = open("./a", O_RDONLY);
  fd2 = open("./b", O_WRONLY | O_CREAT);
  char buf[1024];
  close(1);
  fcntl(fd2, F_DUPFD, 1); // 将fd2,1的文件描述符指向同一个文件
  while ((count = read(fd1, buf, sizeof(buf))) > 0)
  {
    write(fd2, buf, count);
    write(1, buf, count);
  }
  close(fd1);
  close(fd2);
  close(1);
  return 0;
}